import { Body, Controller, Get, Post, UseInterceptors, ClassSerializerInterceptor, BadRequestException, createParamDecorator } from '@nestjs/common';
import { ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';
import { InjectRepository } from '@nestjs/typeorm';
import { Article } from 'src/Entities/Article/Article.dao';
import { User } from 'src/Entities/User/User.dao';
import { Repository } from 'typeorm';
import UserDto from "../../../Dtos/user.dto"
import { UserDetail } from '../../../Entities/User/UserDetail.dao';

@ApiTags("用户模块")
@Controller('user')
export class ControlController {
    constructor(
        @InjectRepository(User) private userRepository: Repository<User>,
        @InjectRepository(UserDetail) private userDetailRepository: Repository<UserDetail>,
        @InjectRepository(Article) private article: Repository<Article>,

    ) {

    }

    @Get("index")
    index() {
        return "hello user"
    }


    @UseInterceptors(ClassSerializerInterceptor)
    @ApiOperation({ description: "获取用户相关信息" })
    @Post("getUser")
    async getUser(@Body() user: UserDto) {
        console.log(user);
        return await this.userRepository.find(

        )
    }

    @ApiOperation({ description: "获取用户详情" })
    @Post("getUserDetail")
    async getUserDetail() {
        return await this.userDetailRepository.find(
            {
                relations: ["user"]
            }
        )
    }


    @Get("getArticle")
    async getArticle() {
        let article = new Article()
        article.content = "hello python"
        article.name = "test"
        return await this.article.save(article)
    }

    @Get("getArticleInfo")
    async getArticleInfo() {
        return {
            code: 200,
            message: "成功",
            data: await this.article.find()
        }
    }


}
